package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CScenicSpots;
import com.ruoyi.camp.service.ICScenicSpotsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地景点Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/camp/spots")
public class CScenicSpotsController extends BaseController
{
    @Autowired
    private ICScenicSpotsService cScenicSpotsService;

    /**
     * 查询营地景点列表
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:list')")
    @GetMapping("/list")
    public TableDataInfo list(CScenicSpots cScenicSpots)
    {
        startPage();
        List<CScenicSpots> list = cScenicSpotsService.selectCScenicSpotsList(cScenicSpots);
        return getDataTable(list);
    }

    /**
     * 导出营地景点列表
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:export')")
    @Log(title = "营地景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CScenicSpots cScenicSpots)
    {
        List<CScenicSpots> list = cScenicSpotsService.selectCScenicSpotsList(cScenicSpots);
        ExcelUtil<CScenicSpots> util = new ExcelUtil<CScenicSpots>(CScenicSpots.class);
        util.exportExcel(response, list, "营地景点数据");
    }

    /**
     * 获取营地景点详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:query')")
    @GetMapping(value = "/{scenicid}")
    public AjaxResult getInfo(@PathVariable("scenicid") String scenicid)
    {
        return success(cScenicSpotsService.selectCScenicSpotsByScenicid(scenicid));
    }

    /**
     * 新增营地景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:add')")
    @Log(title = "营地景点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CScenicSpots cScenicSpots)
    {
        return toAjax(cScenicSpotsService.insertCScenicSpots(cScenicSpots));
    }

    /**
     * 修改营地景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:edit')")
    @Log(title = "营地景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CScenicSpots cScenicSpots)
    {
        return toAjax(cScenicSpotsService.updateCScenicSpots(cScenicSpots));
    }

    /**
     * 删除营地景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:remove')")
    @Log(title = "营地景点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicids}")
    public AjaxResult remove(@PathVariable String[] scenicids)
    {
        return toAjax(cScenicSpotsService.deleteCScenicSpotsByScenicids(scenicids));
    }
}
